package com.atguigu.classroom.result;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@ApiModel("统一返回结果类")
@Data
public class Result<T> {
    @ApiModelProperty("状态码")
    private Integer code;
    @ApiModelProperty("返回状态信息信息")
    private String message;
    @ApiModelProperty("最终返回数据")
    private T data;
    //成功
    public static<T> Result<T> ok(T t){
        Result<T> result=new Result<>();
        result.setCode(200);
        result.setMessage("成功");
        result.setData(t);
        return result;
    }
    //失败
    public static<T> Result<T> fail(){
        Result<T> result=new Result<>();
        result.setCode(400);
        result.setMessage("失败");
        return result;
    }
    //特殊情况修改msg和code值
    public Result<T> message(String msg){
        this.setMessage(msg);
        return this;
    }
    public Result<T> code(Integer code){
        this.setCode(code);
        return this;
    }
}
